package com.dht.xiao.jianye.dialog;

import android.app.Activity;
import android.content.Context;
import android.support.v7.app.AlertDialog;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.dht.xiao.jianye.R;


/**
 * 提示，重新发送，或者报故障
 */

public class RetrySendDialog {
    //@BindView(R.id.bt_cancle)
    TextView btCancle;
    //@BindView(R.id.bt_sure)
    TextView btSure;
    TextView title;
    TextView content;

    private Context context;
    private OnCallBack onCallBack;
    private String string_title,string_content;
    public RetrySendDialog(Context context, String string_title, String string_content) {
        this.context = context;
        this.string_title= string_title;
        this.string_content= string_content;
        DialogInit();
    }

    private void DialogInit() {

        final AlertDialog.Builder Builder =
                new AlertDialog.Builder(context, R.style.DialogHint);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_retry_send, null);
       // ButterKnife.bind(this, view);
        btCancle = (TextView)view.findViewById(R.id.bt_cancle);
        btSure = (TextView)view.findViewById(R.id.bt_sure);
        title =  (TextView)view.findViewById(R.id.title);
        content =  (TextView)view.findViewById(R.id.content);

        title.setText(string_title);
        content.setText(string_content);
        Builder.setView(view);
        final AlertDialog dialog = Builder.show();
        WindowManager.LayoutParams params =
                dialog.getWindow().getAttributes();
        WindowManager manager = ((Activity) context).getWindowManager();
        Display d = manager.getDefaultDisplay(); // 获取屏幕宽、高度
        params.y = 300;
        params.width = (int) (d.getWidth() * 0.8); // 宽度设置为屏幕的0.65，根据实际情况调整
        dialog.getWindow().setAttributes(params);

        btSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onCallBack != null) {
                    onCallBack.sure();
                    dialog.dismiss();
                }
            }
        });
        btCancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onCallBack != null) {
                    onCallBack.cancle();
                    dialog.dismiss();
                }
            }
        });

    }


    public void setOnCallBackListener(OnCallBack onCallBack) {
        this.onCallBack = onCallBack;
    }


    public interface OnCallBack {
        public void sure();
        public void cancle();
    }
}
